#!/usr/bin/python3
import subprocess
import time
import socket
from datetime import datetime
import sys

if len(sys.argv) > 1 and sys.argv[1] == 'test':
    print("do some test cases to activate jit")
    
    HOST = "127.0.0.1"
    PORT = 2077
    
    test_cases = [
                    "FRDFUDBBDFFBDRLLFRLURBFLRUUULBDDUFDULRDLLRLBBRUUFBBFRD",
                    "LDRBUDUBLFRBDRUBRRRLDRFBRDLBLUFDBBLFUUFFLUDUDUFFLBRDFL",
                    "DDBUURUBLFDDLRBFFULLDUFDDBRFRUBDLFLRRRBFLFUDRLFBUBRBUL"
                ]
    
    for test_case in test_cases:
        start_time = datetime.now()
    
        scrambledCube = test_case + "\n"
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.connect((HOST, PORT))
            s.sendall(bytes(("0 5 " + scrambledCube).encode('utf-8')))
            solution = s.recv(1024)
    
        #solution = str(solution, encoding='utf-8')
        #print(solution)
        print(datetime.now() - start_time)
    exit()
else:
    subprocess.Popen("java demo_server", shell=True, cwd="../min2phase/dist")
    print("wait for init...")
    exit()
